home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / docs / hyper / IndexAG.lha / IndexAG / indexagui_func.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-08  |  10.5 KB  |  359 lines

  1. /* C code generated by:                            */
  2. /* Visual Arts Version 2.5                        */
  3. /* Copyright (c)1994-95 Danny Y. Wong  All rights reserved        */
  4. /* Calgary, Alberta (CANADA)                                    */
  5.  
  6. extern struct xword * FindNodeNo(struct List *, UWORD);
  7. extern void IndexAGuiDrawRects(struct Window *Wind);
  8. extern struct Window  *IndexAGuiWnd;
  9. extern struct Gadget *IndexAGuiGadgets[IndexAGuiNumGads];
  10. extern void CreateIndexAGuiLists(void);
  11. extern void SortMinList (struct List *);
  12. extern UBYTE *linksLabels[];
  13. struct List *IndexAGuiLists[1];
  14.  
  15. void IndexAGuiDrawRects(struct Window *Wind)
  16. {
  17.   UWORD offsetx = Scr->WBorLeft;
  18.   UWORD offsety = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  19.  
  20.   SetDrPt(Wind->RPort, 0xFFFF);
  21.   SetOPen(Wind->RPort, 0);
  22.   SetAfPt(Wind->RPort, NULL, 0);
  23. }
  24.  
  25. void CreateIndexAGuiLists(void)
  26. {
  27.   short i;
  28.  
  29.   i=0;
  30.   while (linksLabels[i])
  31.      AddNewNode(IndexAGuiLists[0], linksLabels[i++]);
  32.  
  33. }
  34.  
  35.              /* gadget functions */
  36.  
  37. int butSaveObj(struct VAobject VAObject)
  38. {
  39.         /* Save word list */
  40.         char wordsfile[160];
  41.         struct xword *new;
  42.         BPTR file;
  43.         
  44.         strcpy(wordsfile,Wordpath);
  45.         strcat(wordsfile,"/");
  46.         strcat(wordsfile,WordFile);
  47.         
  48.    if(exwords)
  49.    {
  50.         if(!(file=Open(wordsfile, MODE_NEWFILE)))
  51.         {
  52.                 char errorstr[80]="Can't open file ";
  53.                 strcat(errorstr, WordFile);
  54.                 strcat(errorstr, "for output!");
  55.                 error(errorstr);
  56.         }
  57.         else
  58.         {
  59.         
  60.      for (new= (struct xword *)exwords->lh_Head; new->nextxword.ln_Succ; new=(struct xword *)new->nextxword.ln_Succ)
  61.      { 
  62.         FPuts(file,new->nextxword.ln_Name);             /* release size of word + the NULL */
  63.         FPuts(file,"\n");
  64.      }
  65.    }
  66.    Close(file);
  67.   }
  68.  
  69.    if(!(file=Open("IndexAG.prefs", MODE_NEWFILE)))
  70.                 error("Can't open preference file for output!");
  71.    else
  72.    {
  73.                 char temp[5]="";
  74.                 FPuts(file,Wordpath);
  75.                 FPuts(file,"\n");
  76.                 FPuts(file,WordFile);
  77.                 FPuts(file,"\n");
  78.                 FPuts(file,groupstart);
  79.                 FPuts(file,"\n");
  80.                 FPuts(file,groupend);
  81.                 FPuts(file,"\n");
  82.                 sprintf(temp,"%d\n",threshold);
  83.                 FPuts(file,temp);
  84.                 sprintf(temp,"%d\n",nolinks);
  85.                 FPuts(file,temp);
  86.                 sprintf(temp,"%d\n",-(comment));
  87.                 FPuts(file,temp);
  88.                 Close(file);
  89.    }
  90.   return(1L);
  91. }
  92. /*    Button  Save         */ 
  93.  
  94. int butNewObj(struct VAobject VAObject)
  95. {
  96.         newpress=TRUE;        
  97.         GT_SetGadgetAttrs(IndexAGuiGadgets[ID_strExword], IndexAGuiWnd, NULL, GA_Disabled, FALSE, TAG_END);
  98.         ActivateGadget(IndexAGuiGadgets[ID_strExword], IndexAGuiWnd, NULL);
  99.         
  100.   return(1L);
  101. }
  102. /*    Button  New         */ 
  103.  
  104. int butCreateObj(struct VAobject VAObject)
  105. {
  106.         makeindexfile();
  107.   return(1L);
  108. }
  109. /*    Button  Create Index         */ 
  110.  
  111. int butDeleteObj(struct VAobject VAObject)
  112. {
  113.         struct xword *DelNode;
  114.         if (ListViewitem != ~0)
  115.         {
  116.                 GT_SetGadgetAttrs(IndexAGuiGadgets[ID_listExclude],IndexAGuiWnd, NULL, GTLV_Labels, ~0, TAG_END);
  117.                 DelNode = FindNodeNo(exwords, ListViewitem);
  118.                 FreeMem(DelNode->nextxword.ln_Name, strlen(DelNode->nextxword.ln_Name)+1);
  119.                 Remove((struct Node *)DelNode);
  120.                 GT_SetGadgetAttrs(IndexAGuiGadgets[ID_listExclude],IndexAGuiWnd, NULL, GTLV_Labels, exwords, GTLV_Selected, ~0, TAG_END);
  121.                 GT_SetGadgetAttrs(IndexAGuiGadgets[ID_strExword], IndexAGuiWnd, NULL, GA_Disabled, TRUE, GTST_String, "", TAG_END);
  122.         }
  123.                 
  124.   return(1L);
  125. }
  126. /*    Button  Delete         */ 
  127.  
  128. int strFileObj(struct VAobject VAObject)
  129. {
  130.         strcpy(GuideName,GetString(IndexAGuiGadgets[ID_strFile]));
  131.   return(1L);
  132. }
  133. /*    String  File         */ 
  134.  
  135. int intThresObj(struct VAobject VAObject)
  136. {
  137.   threshold = GetNumber(IndexAGuiGadgets[ID_intThres]);     
  138.   return(1L);
  139. }
  140. /*    Integer  Threshold         */ 
  141.  
  142. int strWordObj(struct VAobject VAObject)
  143. {
  144.         strcpy(WordFile ,GetString(IndexAGuiGadgets[ID_strWord]));
  145.         GT_SetGadgetAttrs(IndexAGuiGadgets[ID_listExclude],IndexAGuiWnd, NULL, GTLV_Labels, ~0, TAG_END);
  146.         readwords();
  147.         GT_SetGadgetAttrs(IndexAGuiGadgets[ID_listExclude],IndexAGuiWnd, NULL, GTLV_Labels, exwords, TAG_END);
  148.  
  149.   return(1L);
  150. }
  151. /*    String  Word File         */ 
  152.  
  153. int strStartObj(struct VAobject VAObject)
  154. {
  155.   strcpy(groupstart,GetString(IndexAGuiGadgets[ID_strStart]));     
  156.   return(1L);
  157. }
  158. /*    String  Start         */ 
  159.  
  160. int strEndObj(struct VAobject VAObject)
  161. {
  162.         strcpy(groupend,GetString(IndexAGuiGadgets[ID_strEnd]));
  163.   return(1L);
  164. }
  165. /*    String  End         */ 
  166.  
  167. int strExwordObj(struct VAobject VAObject)
  168. {
  169.         struct xword *oldword=NULL, *newword;
  170.  
  171.         char *temp=NULL;
  172.         char tempstr[80]="";
  173.         strcpy(tempstr,GetString(IndexAGuiGadgets[ID_strExword]));
  174.         strip(tempstr," ", 'B');
  175.         if (tempstr != "")
  176.       {
  177.         GT_SetGadgetAttrs(IndexAGuiGadgets[ID_listExclude],IndexAGuiWnd, NULL, GTLV_Labels, ~0, TAG_END);
  178.  
  179.         if (newpress== TRUE)
  180.         {
  181.                 if (exwords==NULL)
  182.                 {
  183.                         if(!(exwords=AllocMem(sizeof(struct List), MEMF_CLEAR)))
  184.                                 error("Can't create new word list!");
  185.                         else
  186.                                 NewList(exwords);
  187.                 }
  188.                 
  189.         if (!(newword=AllocMem(sizeof(struct xword),MEMF_CLEAR)))  /* Allocate space for the node */
  190.               error("Not enough memory for newword structure\n");
  191.            else
  192.            {    
  193.               newword->nextxword.ln_Name = NULL;
  194.               if (!(temp=AllocMem(strlen(buffer)+1, MEMF_CLEAR)))  /* Allocate for the word  */
  195.                  error("Not enough memory to store word\n");
  196.               else
  197.               {
  198.                   newword->nextxword.ln_Name = temp;                         /* point our word pointer to the memory allocated */
  199.                   strcpy(temp, tempstr);
  200.                   AddTail((struct List *)exwords, (struct Node *)newword);  /* add it to the list */
  201.               }
  202.            }
  203.         }
  204.  
  205.         else
  206.         {
  207.                 if (!(temp = AllocMem(strlen(tempstr)+1, MEMF_CLEAR)))
  208.                         error("Can't allocate memory for word!");
  209.                 else
  210.                 {        
  211.                         oldword = FindNodeNo(exwords, ListViewitem);
  212.                         FreeMem(oldword->nextxword.ln_Name, strlen(oldword->nextxword.ln_Name)+1);
  213.                 
  214.                          strcpy(temp,tempstr);
  215.                         oldword->nextxword.ln_Name = temp;
  216.                 }
  217.         }
  218.         
  219.         SortMinList(exwords);
  220.       }
  221.         GT_SetGadgetAttrs(IndexAGuiGadgets[ID_listExclude],IndexAGuiWnd, NULL, GTLV_Labels, exwords, GTLV_Selected, ~0, TAG_END);
  222.         GT_SetGadgetAttrs(IndexAGuiGadgets[ID_strExword], IndexAGuiWnd, NULL, GA_Disabled, TRUE, GTST_String, "", TAG_END);
  223.         newpress = FALSE;
  224.         
  225.  
  226.   return(1L);
  227. }
  228. /*    String           */ 
  229.  
  230. int chkCommentObj(struct VAobject VAObject)
  231. {
  232.         comment = !comment;
  233.  
  234.   return(1L);
  235. }
  236.  
  237. void toggleck(void)
  238. {
  239.         comment = !comment;
  240.         GT_SetGadgetAttrs(IndexAGuiGadgets[ID_chkComment],IndexAGuiWnd, NULL, GTCB_Checked, comment, TAG_END);
  241. }
  242.         
  243. /*    Check Box  Comment         */ 
  244.  
  245. int mxLinksObj(struct VAobject VAObject)
  246. {
  247.         int value = VAObject.va_IntuiMsg->Code;
  248.         if (value == 0)
  249.         {
  250.                 nolinks=1;
  251.                 nowords=0;
  252.         }
  253.         else
  254.         {
  255.                 nolinks=0;
  256.                 nowords=1;
  257.         }
  258.  
  259.         
  260.   return(1L);
  261. }
  262.  
  263. void togglemx(void)
  264. {
  265.                 nolinks=!nolinks;
  266.                 nowords=!nowords;
  267.         GT_SetGadgetAttrs(IndexAGuiGadgets[ID_mxLinks],IndexAGuiWnd, NULL, GTMX_Active, !nolinks, TAG_END);
  268. }
  269.  
  270. /*    MX           */ 
  271.  
  272. int listExclude(struct VAobject VAObject)
  273. {
  274.         ListViewitem = VAObject.va_IntuiMsg->Code;
  275.         GT_SetGadgetAttrs(IndexAGuiGadgets[ID_strExword], IndexAGuiWnd, NULL, GA_Disabled, FALSE, TAG_END);
  276.  
  277.   return(1L);
  278. }
  279. /*    ListView  Exclude words         */ 
  280.  
  281. int butFileObj(struct VAobject VAObject)
  282. {
  283.  
  284.  struct TagItem frtags[] =
  285.  {
  286.         ASL_Hail, (ULONG)"Please Choose an AmigaGuide file",
  287.         ASL_Height, 250,
  288.         ASL_Width, 200,
  289.         ASL_LeftEdge, 100,
  290.         ASL_TopEdge, 100,
  291.         ASL_OKText, (ULONG)"OK",
  292.         ASL_CancelText, (ULONG)"Cancel",
  293.         ASL_Pattern, (ULONG)"#?.Guide",
  294.         ASL_Dir, (ULONG)Guidepath,
  295.         ASL_FuncFlags, FILF_PATGAD,
  296.         TAG_DONE
  297.  };
  298.  
  299.         struct FileRequester *fr;
  300.         
  301.         if (AslBase = OpenLibrary("asl.library", 37L))
  302.         {
  303.                 if (fr = (struct FileRequester *)AllocAslRequest(ASL_FileRequest, frtags))
  304.                 {
  305.                         if (AslRequest(fr,NULL))
  306.                         {
  307.                                 strcpy(GuideName,fr->rf_File);
  308.                                 strcpy(Guidepath,fr->rf_Dir);
  309.                                 GT_SetGadgetAttrs(IndexAGuiGadgets[ID_strFile], IndexAGuiWnd, NULL, GTST_String, GuideName, TAG_END);
  310.                         }
  311.                         FreeAslRequest(fr);
  312.                 }
  313.                 CloseLibrary(AslBase);
  314.         }
  315.   return(1L);
  316. }
  317. /*    Hilight  butFileget         */ 
  318.  
  319. int butWords19Obj(struct VAobject VAObject)
  320. {
  321.         
  322.         struct TagItem frtags[] =
  323.  {
  324.         ASL_Hail, (ULONG)"Please choose a word file",
  325.         ASL_Height, 250,
  326.         ASL_Width, 200,
  327.         ASL_LeftEdge, 100,
  328.         ASL_TopEdge, 100,
  329.         ASL_OKText, (ULONG)"OK",
  330.         ASL_CancelText, (ULONG)"Cancel",
  331.         ASL_Dir, (ULONG)Wordpath,
  332.         TAG_DONE
  333.  };
  334.  
  335.  
  336.         struct FileRequester *fr;
  337.         
  338.                 if (AslBase = OpenLibrary("asl.library", 37L))
  339.             {
  340.                 if (fr = (struct FileRequester *)AllocAslRequest(ASL_FileRequest, frtags))
  341.                 {
  342.                         GT_SetGadgetAttrs(IndexAGuiGadgets[ID_listExclude],IndexAGuiWnd, NULL, GTLV_Labels, ~0, TAG_END);
  343.                         if (AslRequest(fr,NULL))
  344.                         {
  345.                                 strcpy(WordFile, fr->rf_File);
  346.                                 strcpy(Wordpath, fr->rf_Dir);
  347.                                 GT_SetGadgetAttrs(IndexAGuiGadgets[ID_strWord], IndexAGuiWnd, NULL, GTST_String, WordFile, TAG_END);
  348.                         }
  349.                         FreeAslRequest(fr);
  350.                 }                
  351.                 CloseLibrary(AslBase); 
  352.                 readwords();
  353.                 GT_SetGadgetAttrs(IndexAGuiGadgets[ID_listExclude],IndexAGuiWnd, NULL, GTLV_Labels, exwords, TAG_END);
  354.             }
  355.   return(1L);
  356. }
  357. /*    Hilight  butWordsget         */ 
  358.  
  359.